<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="${ctxPath!}/layui/css/layui.css" rel="stylesheet" type="text/css">
    <% include("/templates/common/dialog.html"){} %>
    <style>

        .layui-form-item .layui-form-label{
            width:150px;
        }
        .layui-form-item .layui-input-block{
            margin-left: 200px;
        }
    </style>
</head>
<body>
<div style="padding:10px 50px 10px 10px">
    <form id="buildingForm" method="post" action="${ctxPath!}/sys/building/edit" class="layui-form">
        <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc; padding-bottom: 5px;">楼栋信息</div>
        <input type="hidden" name="id" value="${building.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">楼栋名称</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="name" value="${building.name!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">有人云账号</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="account" value="${building.account!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">有人云密码</label>
            <div class="layui-input-block">
                <input class="layui-input" id="password" type="password" name="password" value="${building.password!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input class="layui-input" id="r_password" type="password" name="r_password" value="${building.password!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备ID1</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="buildingId1" value="${building.deviceId1}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备ID2</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="deviceId2" value="${building.deviceId2}"  />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用预测功能</label>
            <div class="layui-input-block">
                <select name="forecast">
                    <option value="true" ${building.forecast != false ? "selected" : ""}>是</option>
                    <option value="false" ${building.forecast == false ? "selected" : ""}>否</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否有人云设备</label>
            <div class="layui-input-block">
                <select name="cloud">
                    <option value="true" ${building.cloud != false ? "selected" : ""}>是</option>
                    <option value="false" ${building.cloud == false ? "selected" : ""}>否</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">进水量下发间隔</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="interval" value="${building.interval!}"  />
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn" lay-submit lay-filter="*">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer=layui.layer;
        form.on('submit(*)', function(data){
            var buildingId = '${building.id}';
            if(!buildingId){
                if($('#password').val() != $('#r_password').val()){
                    layer.alert("两次输入的密码不相同", {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                    return false;
                }
            }
            //index = layer.load(0);
            $.post($("#buildingForm").attr("action"), $("#buildingForm").serialize(), function(data){
                if(data.status == 200){
                    layer.alert(data.msg, {
                        icon: 1,
                        skin: 'layer-ext-moon'
                    },function () {
                        parent.myJqGrid.reloadGrid({});
                        parent.layer.closeAll();
                    });
                }else{
                    layer.alert(data.msg, {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                }
            });
            return false; //阻止表单跳转。
        });
    });
    function closeAll() {
        parent.layer.closeAll();
    }
</script>
</body>
</html>